package com.fingard.dsp.bank.directbank.czb03;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fingard.FGBiz;
import com.fingard.constant.Format;
import com.fingard.db.JDBCHelper;
import com.fingard.dsp.bank.directbank.bankInterface.IElecBillTrans;
import com.fingard.dsp.bank.reqrespobj.elecbilltrans.*;
import com.fingard.dsp.bank.reqrespobj.elecbilltrans.detail.*;
import com.fingard.text.StringHelper;
import com.google.gson.Gson;

import java.sql.Connection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @Description TODO
 * @Author xtt
 * @Date $ $
 **/
public class CZB03ElecBillTrans extends CZB03Base implements IElecBillTrans {
    @Override
    public RetAtsB003BillRespSubmit D_B003_BillResp_Submit(ReqB003BillRespSubmit query) throws Exception {
        RetAtsB003BillRespSubmit b003 = new RetAtsB003BillRespSubmit(query.reqHeader);
        b003.writeStart();
        while (query.readRecord()) {
            HashMap<String, Object> body = new HashMap<String, Object>();
            Map<String, Object> json = new HashMap<String, Object>();
            Map<String, Object> prBill4YqtOutBean = new HashMap<String, Object>();
            prBill4YqtOutBean.put("custAccount", query.detail.actNum);//客户账号
            prBill4YqtOutBean.put("billNo", query.detail.billNo);//票号
            prBill4YqtOutBean.put("warteeSign", "YQDJ");//电子签名，默认YQDJ
            prBill4YqtOutBean.put("responseValue", query.detail.respFlag.equals("1")?"1":"0");//签收标志：1-同意签收；0-驳回
            if(StringHelper.isNullOrEmpty(query.detail.memo)){
                prBill4YqtOutBean.put("toRemark","同意签收");//签收意见，备注信息
            } else {
                prBill4YqtOutBean.put("toRemark",query.detail.memo);//签收意见，备注信息
            }

            if(("1").equals(query.detail.respType)){
                prBill4YqtOutBean.put("curStatus","B_08");//签收类型
            }else if(("2").equals(query.detail.respType)){
                prBill4YqtOutBean.put("curStatus","C_08");//签收类型
            }else if(("3").equals(query.detail.respType)){
                prBill4YqtOutBean.put("curStatus","E_08");//签收类型
            }else if(("4").equals(query.detail.respType)){
                prBill4YqtOutBean.put("curStatus","H_08");//签收类型
            }else if(("5").equals(query.detail.respType)){
                prBill4YqtOutBean.put("curStatus","P_08");//签收类型
            }else if(("6").equals(query.detail.respType)){
                prBill4YqtOutBean.put("curStatus","R_08");//签收类型
            }else if(("7").equals(query.detail.respType)){
                prBill4YqtOutBean.put("curStatus","Q_08");//签收类型
            }else if(("8").equals(query.detail.respType)){
                b003.writeRespInfo("-1");
                b003.writeRespCode("银行暂不支持此类签收");
                b003.writeEnd();
                return b003;
            }else if(query.detail.respType.equals(9)){
                prBill4YqtOutBean.put("curStatus","O_08");//签收类型
            }

            JSONObject billReqInfoJson = new JSONObject(prBill4YqtOutBean);
            body.put("tradeCode", "PJ2019");//交易代码
            body.put("billReqInfo", billReqInfoJson.toString());
            JSONObject bodyInfo = new JSONObject(body);
            CZB03Header czb03Header = new CZB03Header();
            czb03Header.transCode = "42";//API方式
            czb03Header.reqSeqNo = query.reqHeader.transSeqID;
            String reqStr = writeRequestJson(body, czb03Header);
            String[] retStrArr = sendToBank(reqStr);
            if (retStrArr[0].length() == 0) {
                JSONObject repInfo = JSONObject.parseObject(retStrArr[1]);
                if (repInfo != null) {
                    String resultcode = repInfo.getString("resultcode");
                    String resultdesc = repInfo.getString("resultdesc");
                    if (resultcode != null && resultcode.equals("000000")) {
                        //获取body内容
                        String details = repInfo.getString("body");
                        Gson gson = new Gson();
                        JSONObject repBody = JSON.parseObject(details);
                        String errCode = repBody.getString("errCode");
                        String errMsg = repBody.getString("errMsg");
                        if (errCode != null && errCode.equals("000000")) {
                            RetAtsB003BillRespSubmitDetail detail = new  RetAtsB003BillRespSubmitDetail();
                            detail.reqSeqID = query.detail.reqSeqID;
                            detail.respCode = "0";
                            detail.payInfoCode = errCode;
                            detail.respInfo = errMsg;
                            detail.transState = errCode;
                            b003.writeDetail(detail);
                        } else {
                            b003.writeRespInfo("-1");
                            b003.writeRespCode(errMsg);
                        }
                    } else {
                        b003.writeRespInfo("-1");
                        b003.writeRespCode(resultdesc);
                    }
                } else {
                    b003.writeRespInfo("-1");
                    b003.writeRespCode("返回内容为空");
                }
            }else {
                b003.writeRespInfo("-1");
                b003.writeRespCode("请求失败");
            }
        }
        b003.writeEnd();
        return b003;
    }

    @Override
    /**
     * 出票
     */
    public RetAtsB101BillApplySubmit D_B101_BillResp_Submit(ReqB101BillApplySubmit query) throws Exception {
        RetAtsB101BillApplySubmit b101 = new RetAtsB101BillApplySubmit(query.reqHeader);
        b101.writeStart();
        while (query.readRecord()) {
            HashMap<String, Object> body = new HashMap<String, Object>();
            Map<String, Object> json = new HashMap<String, Object>();
            Map<String, Object> prBill4YqtOutBean = new HashMap<String, Object>();
            prBill4YqtOutBean.put("remitterCustAcct", query.detail.drawAct);//出票人账号
            prBill4YqtOutBean.put("warteeSign", "YQDJ");//电子签名，默认YQDJ
            prBill4YqtOutBean.put("isDeliver", query.detail.autoPromptReceipt);//是否自动提示收票：1-自动；0-人工提示收票
            prBill4YqtOutBean.put("batchNo", query.detail.reqSeqID);//批次号
            prBill4YqtOutBean.put("billType", query.detail.billType);
            prBill4YqtOutBean.put("dueDt",Format.Date8Format.format(Format.Date10Format.parse(query.detail.dueDate)));
            prBill4YqtOutBean.put("billMoney", query.detail.billAmt);
            prBill4YqtOutBean.put("payee", query.detail.payeeName);
            prBill4YqtOutBean.put("payeeAcct", query.detail.payeeAct);
            prBill4YqtOutBean.put("payeeBank", query.detail.payeeBnkName);
            prBill4YqtOutBean.put("payeeBankNo", query.detail.payeeBnkCode);
            prBill4YqtOutBean.put("acceptor", query.detail.accpName);
            prBill4YqtOutBean.put("acceptorAcct", query.detail.accpAct);
            prBill4YqtOutBean.put("acceptorBank", query.detail.accpBnkName);
            prBill4YqtOutBean.put("acceptorBankNo", query.detail.accpBnkCode);
            prBill4YqtOutBean.put("protEndors", "0");//禁止背书标记：0-不禁止背书；1-禁止背书
            prBill4YqtOutBean.put("purpose", query.detail.memo);//备注信息
            json.put("remitRegister4YqtOutBean", prBill4YqtOutBean);

            JSONObject billReqInfoJson = new JSONObject(json);
            body.put("tradeCode", "PJ2005");//交易代码
            body.put("billReqInfo", billReqInfoJson.toString());
            JSONObject bodyInfo = new JSONObject(body);
            CZB03Header czb03Header = new CZB03Header();
            czb03Header.transCode = "42";//API方式
            czb03Header.reqSeqNo = query.reqHeader.transSeqID;
            String reqStr = writeRequestJson(body, czb03Header);
            String[] retStrArr = sendToBank(reqStr);
            if (retStrArr[0].length() == 0) {
                JSONObject repInfo = JSONObject.parseObject(retStrArr[1]);
                if (repInfo != null) {
                    String resultcode = repInfo.getString("resultcode");
                    String resultdesc = repInfo.getString("resultdesc");
                    if (resultcode != null && resultcode.equals("000000")) {
                        //获取body内容
                        String details = repInfo.getString("body");
                        Gson gson = new Gson();
                        JSONObject repBody = JSON.parseObject(details);
                        String errCode = repBody.getString("errCode");
                        String errMsg = repBody.getString("errMsg");
                        if (errCode != null && errCode.equals("000000")) {
                            JSONObject billRespInfo = JSON.parseObject(repBody.getString("billRespInfo"));
                            Connection conn = FGBiz.getLocalDbConn();
                            String uuids = UUID.randomUUID().toString().replaceAll("-", "");
                            JDBCHelper.update(conn, INSERTSEQ, new Object[]{uuids, query.reqHeader.bankCode, Format.DateTimeFormat.format(new Date()), query.detail.reqSeqID,billRespInfo.getString("rgctId")});
                            RetAtsB101BillApplySubmitDetail detail = new RetAtsB101BillApplySubmitDetail();
                            detail.reqSeqID = query.detail.reqSeqID;
                            detail.respCode = "0";
                            detail.payInfoCode = errCode;
                            detail.respInfo = errMsg;
                            detail.transState = errCode;
                            b101.writeDetail(detail);
                        } else {
                            b101.writeRespInfo("-1");
                            b101.writeRespCode(errMsg);
                        }
                    } else {
                        b101.writeRespInfo("-1");
                        b101.writeRespCode(resultdesc);
                    }
                } else {
                    b101.writeRespInfo("-1");
                    b101.writeRespCode("返回内容为空");
                }
            } else {
                b101.writeRespInfo("-1");
                b101.writeRespCode("请求失败");
            }
        }
        b101.writeEnd();
        return b101;
    }

    @Override
    public RetAtsB102BillAccpSubmit D_B102_BillResp_Submit(ReqB102BillAccpSubmit query) throws Exception {
        RetAtsB102BillAccpSubmit b102 = new RetAtsB102BillAccpSubmit(query.reqHeader);
        b102.writeStart();
        while (query.readRecord()) {
            HashMap<String, Object> body = new HashMap<String, Object>();
            Map<String, Object> json = new HashMap<String, Object>();
            Map<String, Object> prBill4YqtOutBean = new HashMap<String, Object>();
            prBill4YqtOutBean.put("custAccount", query.detail.actNum);//客户账号
            prBill4YqtOutBean.put("billNos", query.detail.billNo);//是否自动提示收票：1-自动；0-人工提示收票
            prBill4YqtOutBean.put("warteeSign", "YQDJ");//电子签名，默认YQDJ
            prBill4YqtOutBean.put("batchNo", query.detail.reqSeqID);//批次号
            json.put("promptAcceptTran4YqtOutBean", prBill4YqtOutBean);

            JSONObject billReqInfoJson = new JSONObject(json);
            body.put("tradeCode", "PJ0003");//交易代码
            body.put("billReqInfo", billReqInfoJson.toString());
            JSONObject bodyInfo = new JSONObject(body);
            CZB03Header czb03Header = new CZB03Header();
            czb03Header.transCode = "42";//API方式
            czb03Header.reqSeqNo = query.reqHeader.transSeqID;
            String reqStr = writeRequestJson(body, czb03Header);
            String[] retStrArr = sendToBank(reqStr);
            if (retStrArr[0].length() == 0) {
                JSONObject repInfo = JSONObject.parseObject(retStrArr[1]);
                if (repInfo != null) {
                    String resultcode = repInfo.getString("resultcode");
                    String resultdesc = repInfo.getString("resultdesc");
                    if (resultcode != null && resultcode.equals("000000")) {
                        //获取body内容
                        String details = repInfo.getString("body");
                        Gson gson = new Gson();
                        JSONObject repBody = JSON.parseObject(details);
                        String errCode = repBody.getString("errCode");
                        String errMsg = repBody.getString("errMsg");
                        if (errCode != null && errCode.equals("000000")) {
                            RetAtsB102BillAccpSubmitDetail detail = new RetAtsB102BillAccpSubmitDetail();
                            detail.reqSeqID = query.detail.reqSeqID;
                            detail.respCode = "0";
                            detail.payInfoCode = errCode;
                            detail.respInfo = errMsg;
                            detail.transState = errCode;
                            b102.writeDetail(detail);
                        } else {
                            b102.writeRespInfo("-1");
                            b102.writeRespCode(errMsg);
                        }
                    } else {
                        b102.writeRespInfo("-1");
                        b102.writeRespCode(resultdesc);
                    }
                } else {
                    b102.writeRespInfo("-1");
                    b102.writeRespCode("返回内容为空");
                }
            } else {
                b102.writeRespInfo("-1");
                b102.writeRespCode("请求失败");
            }
        }
        b102.writeEnd();
        return b102;
    }

    @Override
    public RetAtsB103BillRetSubmit D_B103_BillResp_Submit(ReqB103BillRetSubmit query) throws Exception {
        RetAtsB103BillRetSubmit b103 = new RetAtsB103BillRetSubmit(query.reqHeader);
        b103.writeStart();
        while (query.readRecord()) {
            HashMap<String, Object> body = new HashMap<String, Object>();
            Map<String, Object> json = new HashMap<String, Object>();
            Map<String, Object> prBill4YqtOutBean = new HashMap<String, Object>();
            prBill4YqtOutBean.put("custAccount", query.detail.actNum);//客户账号
            prBill4YqtOutBean.put("billNos", query.detail.billNo);//是否自动提示收票：1-自动；0-人工提示收票
            prBill4YqtOutBean.put("warteeSign", "YQDJ");//电子签名，默认YQDJ
            prBill4YqtOutBean.put("batchNo", query.detail.reqSeqID);//批次号
            json.put("repealApply4YqtOutBean", prBill4YqtOutBean);

            JSONObject billReqInfoJson = new JSONObject(json);
            body.put("tradeCode", "PJ0016");//交易代码
            body.put("billReqInfo", billReqInfoJson.toString());
            JSONObject bodyInfo = new JSONObject(body);
            CZB03Header czb03Header = new CZB03Header();
            czb03Header.transCode = "42";//API方式
            czb03Header.reqSeqNo = query.reqHeader.transSeqID;
            String reqStr = writeRequestJson(body, czb03Header);
            String[] retStrArr = sendToBank(reqStr);
            if (retStrArr[0].length() == 0) {
                JSONObject repInfo = JSONObject.parseObject(retStrArr[1]);
                if (repInfo != null) {
                    String resultcode = repInfo.getString("resultcode");
                    String resultdesc = repInfo.getString("resultdesc");
                    if (resultcode != null && resultcode.equals("000000")) {
                        //获取body内容
                        String details = repInfo.getString("body");
                        Gson gson = new Gson();
                        JSONObject repBody = JSON.parseObject(details);
                        String errCode = repBody.getString("errCode");
                        String errMsg = repBody.getString("errMsg");
                        if (errCode != null && errCode.equals("000000")) {
                            RetAtsB103BillRetSubmitDetail detail = new RetAtsB103BillRetSubmitDetail();
                            detail.respCode = "0";
                            detail.reqSeqID = query.detail.reqSeqID;
                            detail.payInfoCode = errCode;
                            detail.respInfo = errMsg;
                            detail.transState = errCode;
                            b103.writeDetail(detail);
                        } else {
                            b103.writeRespInfo("-1");
                            b103.writeRespCode(errMsg);
                        }
                    } else {
                        b103.writeRespInfo("-1");
                        b103.writeRespCode(resultdesc);
                    }
                } else {
                    b103.writeRespInfo("-1");
                    b103.writeRespCode("返回内容为空");
                }
            } else {
                b103.writeRespInfo("-1");
                b103.writeRespCode("请求失败");
            }
        }
        b103.writeEnd();
        return b103;
    }

    @Override
    public RetAtsB104BillReceSubmit D_B104_BillResp_Submit(ReqB104BillReceSubmit query) throws Exception {
        RetAtsB104BillReceSubmit b104 = new RetAtsB104BillReceSubmit(query.reqHeader);
        b104.writeStart();
        while (query.readRecord()) {
            HashMap<String, Object> body = new HashMap<String, Object>();
            Map<String, Object> json = new HashMap<String, Object>();
            Map<String, Object> prBill4YqtOutBean = new HashMap<String, Object>();
            prBill4YqtOutBean.put("custAccount", query.detail.actNum);//客户账号
            prBill4YqtOutBean.put("billNos", query.detail.billNo);//是否自动提示收票：1-自动；0-人工提示收票
            prBill4YqtOutBean.put("warteeSign", "YQDJ");//电子签名，默认YQDJ
            prBill4YqtOutBean.put("batchNo", query.detail.reqSeqID);//批次号
            json.put("prBill4YqtOutBean", prBill4YqtOutBean);

            JSONObject billReqInfoJson = new JSONObject(json);
            body.put("tradeCode", "PJ0009");//交易代码
            body.put("billReqInfo", billReqInfoJson.toString());
            JSONObject bodyInfo = new JSONObject(body);
            CZB03Header czb03Header = new CZB03Header();
            czb03Header.transCode = "42";//API方式
            czb03Header.reqSeqNo = query.reqHeader.transSeqID;
            String reqStr = writeRequestJson(body, czb03Header);
            String[] retStrArr = sendToBank(reqStr);
            if (retStrArr[0].length() == 0) {
                JSONObject repInfo = JSONObject.parseObject(retStrArr[1]);
                if (repInfo != null) {
                    String resultcode = repInfo.getString("resultcode");
                    String resultdesc = repInfo.getString("resultdesc");
                    if (resultcode != null && resultcode.equals("000000")) {
                        //获取body内容
                        String details = repInfo.getString("body");
                        Gson gson = new Gson();
                        JSONObject repBody = JSON.parseObject(details);
                        String errCode = repBody.getString("errCode");
                        String errMsg = repBody.getString("errMsg");
                        if (errCode != null && errCode.equals("000000")) {
                            RetAtsB104BillReceSubmitDetail detail = new RetAtsB104BillReceSubmitDetail();
                            detail.respCode = "0";
                            detail.payInfoCode = errCode;
                            detail.respInfo = errMsg;
                            detail.transState = errCode;
                            detail.reqSeqID = query.detail.reqSeqID;
                            b104.writeDetail(detail);
                        } else {
                            b104.writeRespInfo("-1");
                            b104.writeRespCode(errMsg);
                        }
                    } else {
                        b104.writeRespInfo("-1");
                        b104.writeRespCode(resultdesc);
                    }
                } else {
                    b104.writeRespInfo("-1");
                    b104.writeRespCode("返回内容为空");
                }
            } else {
                b104.writeRespInfo("-1");
                b104.writeRespCode("请求失败");
            }
        }
        b104.writeEnd();
        return b104;
    }

    @Override
    public RetAtsB105BillEndoSubmit D_B105_BillResp_Submit(ReqB105BillEndoSubmit query) throws Exception {
        RetAtsB105BillEndoSubmit b105  = new RetAtsB105BillEndoSubmit(query.reqHeader);
        b105.writeStart();
        while (query.readRecord()) {
            HashMap<String, Object> body = new HashMap<String, Object>();
            Map<String, Object> json = new HashMap<String, Object>();
            Map<String, Object> prBill4YqtOutBean = new HashMap<String, Object>();
            prBill4YqtOutBean.put("billNos", query.detail.billNo);
            prBill4YqtOutBean.put("electronUnderwrite", "YQDJ");//电子签名，默认YQDJ
            prBill4YqtOutBean.put("endorseeName", query.detail.receName);//被背书人名称
            prBill4YqtOutBean.put("endorseeCustAccount", query.detail.receAct);//被背书人账号
            prBill4YqtOutBean.put("endorseeBankNo", query.detail.receBnkCode);//被背书人行号
            prBill4YqtOutBean.put("cessionFlag", query.detail.transFlag);//
            prBill4YqtOutBean.put("custAccount", query.detail.actNum);//
            prBill4YqtOutBean.put("fromRemark", query.detail.memo);//备注
            prBill4YqtOutBean.put("batNo", query.detail.reqSeqID);//批次号
            json.put("endorsement4YqtOutBean", prBill4YqtOutBean);

            JSONObject billReqInfoJson = new JSONObject(json);
            body.put("tradeCode", "PJ0018");//交易代码
            body.put("billReqInfo", billReqInfoJson.toString());
            JSONObject bodyInfo = new JSONObject(body);
            CZB03Header czb03Header = new CZB03Header();
            czb03Header.transCode = "42";//API方式
            czb03Header.reqSeqNo = query.reqHeader.transSeqID;
            String reqStr = writeRequestJson(body, czb03Header);
            String[] retStrArr = sendToBank(reqStr);
            if (retStrArr[0].length() == 0) {
                JSONObject repInfo = JSONObject.parseObject(retStrArr[1]);
                if (repInfo != null) {
                    String resultcode = repInfo.getString("resultcode");
                    String resultdesc = repInfo.getString("resultdesc");
                    if (resultcode != null && resultcode.equals("000000")) {
                        //获取body内容
                        String details = repInfo.getString("body");
                        Gson gson = new Gson();
                        JSONObject repBody = JSON.parseObject(details);
                        String errCode = repBody.getString("errCode");
                        String errMsg = repBody.getString("errMsg");
                        if (errCode != null && errCode.equals("000000")) {
                            RetAtsB105BillEndoSubmitDetail detail = new RetAtsB105BillEndoSubmitDetail();
                            detail.respCode = "0";
                            detail.reqSeqID = query.detail.reqSeqID;
                            detail.payInfoCode = errCode;
                            detail.respInfo = errMsg;
                            detail.transState = errCode;
                            b105.writeDetail(detail);
                        } else {
                            b105.writeRespInfo("-1");
                            b105.writeRespCode(errMsg);
                        }
                    } else {
                        b105.writeRespInfo("-1");
                        b105.writeRespCode(resultdesc);
                    }
                } else {
                    b105.writeRespInfo("-1");
                    b105.writeRespCode("返回内容为空");
                }
            } else {
                b105.writeRespInfo("-1");
                b105.writeRespCode("请求失败");
            }
        }
        b105.writeEnd();
        return b105;
    }

    @Override
    public RetAtsB106BillDiscSubmit D_B106_BillResp_Submit(ReqB106BillDiscSubmit query) throws Exception {
        RetAtsB106BillDiscSubmit b106 = new RetAtsB106BillDiscSubmit(query.reqHeader);
        b106.writeStart();
        while (query.readRecord()) {
            HashMap<String, Object> body = new HashMap<String, Object>();
            Map<String, Object> json = new HashMap<String, Object>();
            Map<String, Object> prBill4YqtOutBean = new HashMap<String, Object>();
            prBill4YqtOutBean.put("billNos", query.detail.billNo);
            prBill4YqtOutBean.put("discType", "0");//贴现方式：0－买断式；1-赎回式(暂不支持)
            prBill4YqtOutBean.put("discRate", query.detail.payInterestRate);//贴现利率，值在0和1之间
            prBill4YqtOutBean.put("discDate", query.detail.discDate.replace("-", ""));//贴现日期，格式：yyyyMMdd
            prBill4YqtOutBean.put("custAcctNo", query.detail.actNum);//客户贴现账号(客户账号)
            prBill4YqtOutBean.put("toCustName", query.detail.receBnkName);//
            prBill4YqtOutBean.put("toCustNo", query.detail.receBnkCode);//
            prBill4YqtOutBean.put("toCustAcct", query.detail.receAct);
            prBill4YqtOutBean.put("elecSign", "YQDJ");//电子签名，默认传YQDJ
            prBill4YqtOutBean.put("batch_no", query.detail.reqSeqID);//
            prBill4YqtOutBean.put("inAcctNo", query.detail.actedAct);//
            prBill4YqtOutBean.put("inBankNo", query.detail.actedBnkCode);//
            prBill4YqtOutBean.put("forbidFlag", query.detail.transFlag.equals("1") ? "0" : "1");//
            prBill4YqtOutBean.put("payType", query.detail.payInterestType.equals("1") ? "2" : "1");//
            prBill4YqtOutBean.put("isOnline", query.detail.payType.equals("0") ? "2" : "1");//

            json.put("custDiscBean4YqtOutBean", prBill4YqtOutBean);

            JSONObject billReqInfoJson = new JSONObject(json);
            body.put("tradeCode", "PJ0018");//交易代码
            body.put("billReqInfo", billReqInfoJson.toString());
            JSONObject bodyInfo = new JSONObject(body);
            CZB03Header czb03Header = new CZB03Header();
            czb03Header.transCode = "42";//API方式
            czb03Header.reqSeqNo = query.reqHeader.transSeqID;
            String reqStr = writeRequestJson(body, czb03Header);
            String[] retStrArr = sendToBank(reqStr);
            if (retStrArr[0].length() == 0) {
                JSONObject repInfo = JSONObject.parseObject(retStrArr[1]);
                if (repInfo != null) {
                    String resultcode = repInfo.getString("resultcode");
                    String resultdesc = repInfo.getString("resultdesc");
                    if (resultcode != null && resultcode.equals("000000")) {
                        //获取body内容
                        String details = repInfo.getString("body");
                        Gson gson = new Gson();
                        JSONObject repBody = JSON.parseObject(details);
                        String errCode = repBody.getString("errCode");
                        String errMsg = repBody.getString("errMsg");
                        if (errCode != null && errCode.equals("000000")) {
                            RetAtsB106BillDiscSubmitDetail detail = new RetAtsB106BillDiscSubmitDetail();
                            detail.respCode = "0";
                            detail.reqSeqID = query.detail.reqSeqID;
                            detail.payInfoCode = errCode;
                            detail.respInfo = errMsg;
                            detail.transState = errCode;
                            b106.writeDetail(detail);
                        } else {
                            b106.writeRespInfo("-1");
                            b106.writeRespCode(errMsg);
                        }
                    } else {
                        b106.writeRespInfo("-1");
                        b106.writeRespCode(resultdesc);
                    }
                } else {
                    b106.writeRespInfo("-1");
                    b106.writeRespCode("返回内容为空");
                }
            } else {
                b106.writeRespInfo("-1");
                b106.writeRespCode("请求失败");
            }
        }
        b106.writeEnd();
        return b106;
    }

    @Override
    public RetAtsB107BillPledSubmit D_B107_BillResp_Submit(ReqB107BillPledSubmit query) throws Exception {
        RetAtsB107BillPledSubmit b107  = new RetAtsB107BillPledSubmit(query.reqHeader);
        b107.writeStart();
        while (query.readRecord()) {
            HashMap<String, Object> body = new HashMap<String, Object>();
            Map<String, Object> json = new HashMap<String, Object>();
            Map<String, Object> prBill4YqtOutBean = new HashMap<String, Object>();
            prBill4YqtOutBean.put("custAccount", query.detail.actNum);//客户账号
            prBill4YqtOutBean.put("billNos", query.detail.billNo);//票号
            prBill4YqtOutBean.put("pawneeName", query.detail.receName);
            prBill4YqtOutBean.put("pawneeAccount", query.detail.receAct);
            prBill4YqtOutBean.put("pawneeBankNo", query.detail.receBnkCode);
            prBill4YqtOutBean.put("electronUnderwrite", "YQDJ");//
            prBill4YqtOutBean.put("batchNo", query.detail.reqSeqID);//
            prBill4YqtOutBean.put("fromRemark", "0");//1-入池质押；0或其他-普通质押；

            json.put("impawn4YqtOutBean", prBill4YqtOutBean);

            JSONObject billReqInfoJson = new JSONObject(json);
            body.put("tradeCode", "PJ2003");//交易代码
            body.put("billReqInfo", billReqInfoJson.toString());
            JSONObject bodyInfo = new JSONObject(body);
            CZB03Header czb03Header = new CZB03Header();
            czb03Header.transCode = "42";//API方式
            czb03Header.reqSeqNo = query.reqHeader.transSeqID;
            String reqStr = writeRequestJson(body, czb03Header);
            String[] retStrArr = sendToBank(reqStr);
            if (retStrArr[0].length() == 0) {
                JSONObject repInfo = JSONObject.parseObject(retStrArr[1]);
                if (repInfo != null) {
                    String resultcode = repInfo.getString("resultcode");
                    String resultdesc = repInfo.getString("resultdesc");
                    if (resultcode != null && resultcode.equals("000000")) {
                        //获取body内容
                        String details = repInfo.getString("body");
                        Gson gson = new Gson();
                        JSONObject repBody = JSON.parseObject(details);
                        String errCode = repBody.getString("errCode");
                        String errMsg = repBody.getString("errMsg");
                        if (errCode != null && errCode.equals("000000")) {
                            RetAtsB107BillPledSubmitDetail detail = new RetAtsB107BillPledSubmitDetail();
                            detail.respCode = "0";
                            detail.reqSeqID = query.detail.reqSeqID;
                            detail.payInfoCode = errCode;
                            detail.respInfo = errMsg;
                            detail.transState = errCode;
                            b107.writeDetail(detail);
                        } else {
                            b107.writeRespInfo("-1");
                            b107.writeRespCode(errMsg);
                        }
                    } else {
                        b107.writeRespInfo("-1");
                        b107.writeRespCode(resultdesc);
                    }
                } else {
                    b107.writeRespInfo("-1");
                    b107.writeRespCode("返回内容为空");
                }
            } else {
                b107.writeRespInfo("-1");
                b107.writeRespCode("请求失败");
            }
        }
        b107.writeEnd();
        return b107;
    }

    @Override
    public RetAtsB108BillPaySubmit D_B108_BillResp_Submit(ReqB108BillPaySubmit query) throws Exception {
        RetAtsB108BillPaySubmit b108  = new RetAtsB108BillPaySubmit(query.reqHeader);
        b108.writeStart();
        while (query.readRecord()) {
            HashMap<String, Object> body = new HashMap<String, Object>();
            Map<String, Object> json = new HashMap<String, Object>();
            Map<String, Object> prBill4YqtOutBean = new HashMap<String, Object>();
            prBill4YqtOutBean.put("billNos", query.detail.billNo);
            prBill4YqtOutBean.put("electronUnderwrite", "YQDJ");//电子签名，默认传YQDJ
            prBill4YqtOutBean.put("promptPaymentDate", Format.Date8Format.format(new Date()));//贴现日期，格式：yyyyMMdd
            prBill4YqtOutBean.put("overdueReason", query.detail.overDueRea);//
            prBill4YqtOutBean.put("settlementFlag", query.detail.payType.equals("1") ? "1" : "0");//
            prBill4YqtOutBean.put("custAccount", query.detail.actNum);
            prBill4YqtOutBean.put("isDelegate", "1");//是否待客托收：1-是；0-否
            prBill4YqtOutBean.put("batNo", query.detail.reqSeqID);

            json.put("promptPayment4YqtOutBean", prBill4YqtOutBean);

            JSONObject billReqInfoJson = new JSONObject(json);
            body.put("tradeCode", "PJ2009");//交易代码
            body.put("billReqInfo", billReqInfoJson.toString());
            JSONObject bodyInfo = new JSONObject(body);
            CZB03Header czb03Header = new CZB03Header();
            czb03Header.transCode = "42";//API方式
            czb03Header.reqSeqNo = query.reqHeader.transSeqID;
            String reqStr = writeRequestJson(body, czb03Header);
            String[] retStrArr = sendToBank(reqStr);
            if (retStrArr[0].length() == 0) {
                JSONObject repInfo = JSONObject.parseObject(retStrArr[1]);
                if (repInfo != null) {
                    String resultcode = repInfo.getString("resultcode");
                    String resultdesc = repInfo.getString("resultdesc");
                    if (resultcode != null && resultcode.equals("000000")) {
                        //获取body内容
                        String details = repInfo.getString("body");
                        Gson gson = new Gson();
                        JSONObject repBody = JSON.parseObject(details);
                        String errCode = repBody.getString("errCode");
                        String errMsg = repBody.getString("errMsg");
                        if (errCode != null && errCode.equals("000000")) {
                            RetAtsB108BillPaySubmitDetail detail = new RetAtsB108BillPaySubmitDetail();
                            detail.respCode = "0";
                            detail.reqSeqID = query.detail.reqSeqID;
                            detail.payInfoCode = errCode;
                            detail.respInfo = errMsg;
                            detail.transState = errCode;
                            b108.writeDetail(detail);
                        } else {
                            b108.writeRespInfo("-1");
                            b108.writeRespCode(errMsg);
                        }
                    } else {
                        b108.writeRespInfo("-1");
                        b108.writeRespCode(resultdesc);
                    }
                } else {
                    b108.writeRespInfo("-1");
                    b108.writeRespCode("返回内容为空");
                }
            } else {
                b108.writeRespInfo("-1");
                b108.writeRespCode("请求失败");
            }
        }
        b108.writeEnd();
        return b108;
    }

    /**
     * 参数对应不上
     * @param query
     * @return
     * @throws Exception
     */
    @Override
    public RetAtsB109BillGuarSubmit D_B109_BillResp_Submit(ReqB109BillGuarSubmit query) throws Exception {
        RetAtsB109BillGuarSubmit b109  = new RetAtsB109BillGuarSubmit(query.reqHeader);
        b109.writeStart();
        while (query.readRecord()) {
            HashMap<String, Object> body = new HashMap<String, Object>();
            Map<String, Object> json = new HashMap<String, Object>();
            Map<String, Object> prBill4YqtOutBean = new HashMap<String, Object>();
            prBill4YqtOutBean.put("custAccount", query.detail.actNum);
            prBill4YqtOutBean.put("billNo", query.detail.billNo);
            prBill4YqtOutBean.put("warteeOrgCode", query.detail.receName);
            //  prBill4YqtOutBean.put("overdueReason", query.detail.overDueRea);//
            //  prBill4YqtOutBean.put("settlementFlag", query.detail.payType.equals("1")?"1":"0");//
            prBill4YqtOutBean.put("warteeName", query.detail.receName);
            prBill4YqtOutBean.put("isDelegate", "1");//是否待客托收：1-是；0-否
            prBill4YqtOutBean.put("batNo", query.detail.reqSeqID);

            json.put("ensureBillInfo4YqtOutBean", prBill4YqtOutBean);

            JSONObject billReqInfoJson = new JSONObject(json);
            body.put("tradeCode", "PJ2029");//交易代码
            body.put("billReqInfo", billReqInfoJson.toString());
            JSONObject bodyInfo = new JSONObject(body);
            CZB03Header czb03Header = new CZB03Header();
            czb03Header.transCode = "42";//API方式
            czb03Header.reqSeqNo = query.reqHeader.transSeqID;
            String reqStr = writeRequestJson(body, czb03Header);
            String[] retStrArr = sendToBank(reqStr);
            if (retStrArr[0].length() == 0) {
                JSONObject repInfo = JSONObject.parseObject(retStrArr[1]);
                if (repInfo != null) {
                    String resultcode = repInfo.getString("resultcode");
                    String resultdesc = repInfo.getString("resultdesc");
                    if (resultcode != null && resultcode.equals("000000")) {
                        //获取body内容
                        String details = repInfo.getString("body");
                        Gson gson = new Gson();
                        JSONObject repBody = JSON.parseObject(details);
                        String errCode = repBody.getString("errCode");
                        String errMsg = repBody.getString("errMsg");
                        if (errCode != null && errCode.equals("000000")) {
                            RetAtsB109BillGuarSubmitDetail detail = new RetAtsB109BillGuarSubmitDetail();
                            detail.respCode = "0";
                            detail.reqSeqID = query.detail.reqSeqID;
                            detail.payInfoCode = errCode;
                            detail.respInfo = errMsg;
                            detail.transState = errCode;
                            b109.writeDetail(detail);
                        } else {
                            b109.writeRespInfo("-1");
                            b109.writeRespCode(errMsg);
                        }
                    } else {
                        b109.writeRespInfo("-1");
                        b109.writeRespCode(resultdesc);
                    }
                } else {
                    b109.writeRespInfo("-1");
                    b109.writeRespCode("返回内容为空");
                }
            } else {
                b109.writeRespInfo("-1");
                b109.writeRespCode("请求失败");
            }
        }
        b109.writeEnd();
        return b109;
    }

    @Override
    /**    保证申请 浙商银行不支持*/
    public RetAtsB110BillRecoSubmit D_B110_BillResp_Submit(ReqB110BillRecoSubmit query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB111BillAgreeSubmit D_B111_BillResp_Submit(ReqB111BillAgreeSubmit query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB112BillCancSubmit D_B112_BillResp_Submit(ReqB112BillCancSubmit query) throws Exception {
        RetAtsB112BillCancSubmit b112 = new RetAtsB112BillCancSubmit(query.reqHeader);
        b112.writeStart();
        while (query.readRecord()) {
            HashMap<String, Object> body = new HashMap<String, Object>();
            Map<String, Object> json = new HashMap<String, Object>();
            Map<String, Object> prBill4YqtOutBean = new HashMap<String, Object>();
            prBill4YqtOutBean.put("custAccount", query.detail.actNum);
            prBill4YqtOutBean.put("billNos", query.detail.billNo);//贴现日期，格式：yyyyMMdd
            prBill4YqtOutBean.put("electronUnderwrite", "YQDJ");//电子签名，默认传YQDJ

            if (query.detail.cancelType.equals("1")) {
                json.put("promptAcceptTran4YqtOutBean", prBill4YqtOutBean);
                body.put("tradeCode", "PJ0006");//交易代码
            } else if (query.detail.cancelType.equals("2")) {
                json.put("prBill4YqtOutBean", prBill4YqtOutBean);
                body.put("tradeCode", "PJ0012");//交易代码
            } else if (query.detail.cancelType.equals("3")) {
                json.put("endorsement4YqtOutBean", prBill4YqtOutBean);
                body.put("tradeCode", "PJ0020");//交易代码
            } else if (query.detail.cancelType.equals("4")) {
                json.put("custDiscBean4YqtOutBean", prBill4YqtOutBean);
                body.put("tradeCode", "PJ2013");//交易代码
            } else if (query.detail.cancelType.equals("5")) {
                json.put("impawn4YqtOutBean", prBill4YqtOutBean);
                body.put("tradeCode", "PJ0031");//交易代码
            } else if (query.detail.cancelType.equals("6")) {
                json.put("promptPayment4YqtOutBean", prBill4YqtOutBean);
                body.put("tradeCode", "PJ2016");//交易代码
            } else if (query.detail.cancelType.equals("8") || query.detail.cancelType.equals("7")) {
                json.put("ensureBillInfo4YqtOutBean", prBill4YqtOutBean);
                body.put("tradeCode", "PJ2032");//交易代码
            } else if (query.detail.cancelType.equals("12")) {
                json.put("impawn4YqtOutBean", prBill4YqtOutBean);
                body.put("tradeCode", "PJ0031");//交易代码
            } else {
                b112.writeRespInfo("-1");
                b112.writeRespCode("暂不支持此类撤销");
                b112.writeEnd();
                return b112;
            }

            JSONObject billReqInfoJson = new JSONObject(json);
            body.put("billReqInfo", billReqInfoJson.toString());
            JSONObject bodyInfo = new JSONObject(body);
            CZB03Header czb03Header = new CZB03Header();
            czb03Header.transCode = "42";//API方式
            czb03Header.reqSeqNo = query.reqHeader.transSeqID;
            String reqStr = writeRequestJson(body, czb03Header);
            String[] retStrArr = sendToBank(reqStr);
            if (retStrArr[0].length() == 0) {
                JSONObject repInfo = JSONObject.parseObject(retStrArr[1]);
                if (repInfo != null) {
                    String resultcode = repInfo.getString("resultcode");
                    String resultdesc = repInfo.getString("resultdesc");
                    if (resultcode != null && resultcode.equals("000000")) {
                        //获取body内容
                        String details = repInfo.getString("body");
                        Gson gson = new Gson();
                        JSONObject repBody = JSON.parseObject(details);
                        String errCode = repBody.getString("errCode");
                        String errMsg = repBody.getString("errMsg");
                        if (errCode != null && errCode.equals("000000")) {
                            RetAtsB112BillCancSubmitDetail detail = new RetAtsB112BillCancSubmitDetail();
                            detail.respCode = "0";
                            detail.reqSeqID = query.detail.reqSeqID;
                            detail.payInfoCode = errCode;
                            detail.respInfo = errMsg;
                            detail.transState = errCode;
                            b112.writeDetail(detail);
                        } else {
                            b112.writeRespInfo("-1");
                            b112.writeRespCode(errMsg);
                        }
                    } else {
                        b112.writeRespInfo("-1");
                        b112.writeRespCode(resultdesc);
                    }
                } else {
                    b112.writeRespInfo("-1");
                    b112.writeRespCode("返回内容为空");
                }
            } else {
                b112.writeRespInfo("-1");
                b112.writeRespCode("请求失败");
            }
        }
        b112.writeEnd();
        return b112;
    }

    @Override
    public RetAtsB113ProtocolSubmit D_B113_ProtocolResp_Submit(ReqB113ProtocolSubmit query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB119BillRelePledSubmit D_B119_BillResp_Submit(ReqB119BillRelePledSubmit query) throws Exception {
        return null;
    }
}
